<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t("面试候选人") }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('候选人名称')">
        <el-input
          v-model="queryParams.candidateName"
          :placeholder="$t('候选人名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('面试岗位')">
        <el-select v-model="queryParams.interviewPost" placeholder="请选择岗位">
          <el-option
            v-for="item in dict.interviewPostArr"
            :key="item.dictValue"
            :label="item.dictLabel"
            clearable
            :value="item.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('工作年限')">
        <el-input
          v-model="queryParams.workYear"
          :placeholder="$t('工作年限')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('期望薪资')">
        <el-input
          v-model="queryParams.expectSalary"
          :placeholder="$t('期望薪资')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('所在城市')">
        <el-select v-model="queryParams.cityRegistered" placeholder="请选择">
          <el-option
            v-for="item in dict.cityArr"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('面试人')">
        <el-input
          v-model="queryParams.nickName"
          :placeholder="$t('面试人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="queryHandle"
        >{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{
          $t("重置")
        }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:interview:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:interview:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t('导出') }}</el-button>
      </el-col> -->
    </el-row>

    <el-table
      v-loading="loading"
      :data="hrInterviewList"
      border
      tooltip-effect="darkTable"
    >
      <el-table-column
        :label="$t('序号')"
        type="index"
        align="center"
        show-overflow-tooltip
        width="50"
      >
        <template slot-scope="scope">
          {{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('候选人名称')"
        align="center"
        prop="candidateName"
      />
      <el-table-column
        :label="$t('面试岗位')"
        align="center"
        prop="interviewPost"
      >
        <template slot-scope="scope">
          <span>{{
            getDictVaule("interviewPostArr", scope.row.interviewPost)
          }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('工作年限')" align="center" prop="workYear" />
      <el-table-column
        :label="$t('期望薪资')"
        align="center"
        prop="expectSalary"
      />
      <el-table-column
        :label="$t('所在城市')"
        align="center"
        prop="city"
      />
      <el-table-column
        :label="$t('面试人')"
        align="center"
        prop="nickName"
      />
      <el-table-column :label="$t('审批状态')" show-overflow-tooltip align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('创建时间')"
        align="center"
        prop="createTime"
      />
      <el-table-column
        :label="$t('操作')"
        align="center"
        class-name="small-padding fixed-width"
        width="200"
      >
        <template slot-scope="scope">
          <!-- <el-button
            v-hasPermi="['system:interview:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
            >{{ $t("修改") }}</el-button
          >
          <el-button
            v-hasPermi="['system:interview:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
            >{{ $t("删除") }}</el-button
          > -->
          <el-button v-show="scope.row.actStatus=='W'" type="text" @click="addHandle(scope.row)">维护实际入职</el-button>
          <ListBtn :bus-data="scope.row" has-permi="oa:interview" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog
      :title="$t(title)"
      :visible.sync="formOpen"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm"
      append-to-body
    >
      <hrInterviewForm ref="hrInterviewForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listHrInterview,
  delHrInterview,
  exportHrInterview
} from '@/api/oa/hr/hrInterview'
import hrInterviewForm from './hrInterviewForm.vue'
export default {
  components: {
    hrInterviewForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      hrInterviewList: [],
      // 弹出层标题
      title: '填写面试候选人信息',
      // 是否显示弹出层
      formOpen: false,
        // 审批状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        candidateName: undefined,
        interviewPost: undefined,
        workYear: undefined,
        expectSalary: undefined,
        city: undefined,
        address: undefined,
        interviewPerson: undefined,
        interviewResult: undefined,
        entryStatus: undefined,
        entryStatusRemark: undefined,
        otherRemark: undefined,
        actId: undefined,
        actStatus: undefined,
          nickName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      dict: {
        interviewPostArr: [],
        cityArr: []
      }
    }
  },
  created() {
    this.getList()
    this.getDicts('interview_gw').then((response) => {
      this.dict.interviewPostArr = response.data
    })
     this.getDicts('work_flow_status').then(response => {
          this.statusOptions = response.data
      })
      this.getDicts('oa_city').then((response) => {
        this.dict.cityArr = response.data
      })
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      listHrInterview(this.queryParams).then((response) => {
        this.hrInterviewList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    // 表单重置
    reset() {
      this.form = {
        id: undefined,

        candidateName: undefined,

        interviewPost: undefined,

        workYear: undefined,

        expectSalary: undefined,

        city: undefined,

        address: undefined,

        interviewPerson: undefined,

        interviewResult: undefined,

        remark: undefined,

        entryStatus: '0',

        entryStatusRemark: undefined,

        otherRemark: undefined,

        delFlag: undefined,

        actId: undefined,

        actStatus: '0'
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryParams = {
        candidateName: undefined,
        interviewPost: undefined,
        workYear: undefined,
        expectSalary: undefined,
        city: undefined,
        nickName: undefined,
        pageNum: 1,
        pageSize: 10
     }
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.hrInterviewForm.init(row, true)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.hrInterviewForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return delHrInterview(row.id)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        })
        .catch(function() {})
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return exportHrInterview(queryParams)
        })
        .then((response) => {
          this.download(response.msg)
        })
        .catch(function() {})
    },
    getDictVaule(listName, key) {
      const list = this.dict[listName]
      for (let i = 0; i < list.length; i++) {
        const dict = list[i]
        if (dict.dictValue === key) {
          return dict.dictLabel
        }
      }
    }
  }
}
</script>
